
var lotteryInit = (function(){

    var lottery = {
        parentEleObj: document.getElementsByClassName('wrapper')[0],
        basicRound: 15,
        myDeg: 0,
        isPreviousTurnEnd: true,
        tablePan: null,
        clickBtn: null,
        getEles: function(el) {
            var elems = el.getElementsByTagName('div');
            this.tablePan = elems[0]; 
            this.clickBtn = elems[1];
        },
        init: function() {
            this.getEles(this.parentEleObj);
            // console.log(this);
            this.eventAdd();
        },
        eventAdd: function() {
            var that = this;
            addEvent(this.clickBtn, 'click', function(){
                if(that.isPreviousTurnEnd) {
                    that.myDeg = that.selectFrom(0, 360);
                    var deg = that.myDeg + that.basicRound * 360;
                    that.tablePan.style.transition = 'all 6s';
                    that.tablePan.style.transform = 'rotate(' + deg + 'deg)';
                    that.isPreviousTurnEnd = false;
                }
            });
            addEvent(this.tablePan, 'webkitTransitionEnd', function(){
                this.style.transition = 'none';
                this.style.transform = 'rotate(' + that.myDeg + 'deg)';           
                that.judge();
                that.isPreviousTurnEnd = true;
            });
        },
        selectFrom: function(lowerValue, upperValue) {
           return Math.floor(Math.random()*(upperValue - lowerValue + 1) + lowerValue);
        },
        judge: function() {
            var deg = this.myDeg;
            if(deg > 180 && deg < 225){
                alert('大吉大利，运气贼佳，恭喜获得一等奖！！！');
            }else if(deg > 0 && deg < 45) {
                alert('大吉大利，运气不错哦，恭喜获得二等奖！！！');
            }else if((deg > 90 && deg < 135)||(deg > 270 && deg < 315)) {
                alert('大吉大利，运气还可以，恭喜获得三等奖！！！');
            }else{
                alert('恭喜恭喜，您获得了四等奖，再接再厉哦！！！');
            }
        }
    }
    return function(){
        lottery.init();
    };

}());

lotteryInit();



